package asteroids.model.programs.parsing.expressions;

import java.util.Map;

import be.kuleuven.cs.som.annotate.Basic;

import asteroids.model.Ship;
import asteroids.model.programs.parsing.types.*;

/**
 * A class of variable expressions.
 * A variable expression is just a variable.
 * 
 * @author Thijs Dieltjens - Wim Konings
 * @version 2.0
 */
public class VariableExpr extends NullaryExpression{

	public VariableExpr(String name,int line, int column) {
		super(line, column);
		this.name=name;
	}

	@Basic
	public String getName(){
		return name;
	}

	private String name;

	@Override
	public Type eval(Ship ship, Map<String, Type> globals){
		if(ship!=null){
			return ((Ship) ship).getProgram().getVariableValue(getName());
		}
		else if(globals!=null){
			return globals.get(getName());
		}
		return new DoubleLiteral();
	}
}
